import typing as T
from fastapi import Depends
from openai import AsyncOpenAI, OpenAI
import logging
from .Global import ENV

async_openai_client: AsyncOpenAI = AsyncOpenAI(
    api_key=ENV.API_KEY, base_url=ENV.BASE_URL
)


def get_temp_client() -> OpenAI:
    return OpenAI(api_key=ENV.API_KEY, base_url=ENV.BASE_URL)


def get_temp_async_client() -> AsyncOpenAI:
    return AsyncOpenAI(api_key=ENV.API_KEY, base_url=ENV.BASE_URL)


async def get_openai_client():
    try:
        yield async_openai_client
    finally:
        ...


OpenAISession = T.Annotated[AsyncOpenAI, Depends(get_openai_client)]  # openai异步客户端

logging.info("openai客户端初始化完成...")
